﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using WinnerCMS.Common;
namespace WinnerCMS.CacheStorager
{
    /// <summary>
    /// 缓存功能主体类
    /// </summary>
    public class CMSCaches
    {
        private static readonly ICacheStorager Cs;
        private static readonly object SyncRoot = new Object();
        private static readonly MemcachedConfig MemCachedConfigInfo;
        static CMSCaches()
        {
            if (MemCachedConfigInfo == null)
            {
                lock (SyncRoot)
                {
                    if (MemCachedConfigInfo == null)
                    {
                        MemCachedConfigInfo = SerializableHelper.DeSerialize<MemcachedConfig>(new FileInfo(HttpServer.MapPath("~\\Config\\WinnerCMS.Memcached.config")));
                    }
                }
            }
            //策略模式实现算法切换
            if (MemCachedConfigInfo != null && MemCachedConfigInfo.Enable)
            {
                Cs = new MemCachedStorager();
            }
            else
            {
                Cs = new RunTimeCacheStorager();
            }
        }
        /// <summary>
        /// 当前存储器
        /// </summary>
        public static ICacheStorager Context
        {
            get
            {
                return Cs;
            }
        }

    }
}